package tianxing

import (
	"encoding/json"
	"fmt"
	ms "gin_template/core/request"
	"strconv"
	"strings"

	"go.uber.org/zap"
)

type holidayResult struct {
	Common
	Newslist []holidayValue `json:"newslist"`
}

type holidayValue struct {
	Date       string `json:"date"`
	Daycode    uint   `json:"daycode"`
	Cnweekday  string `json:"cnweekday"`
	Lunaryear  string `json:"lunaryear"`
	Lunarmonth string `json:"lunarmonth"`
	Lunarday   string `json:"lunarday"`
	Info       string `json:"info"`
	Name       string `json:"name"`
	Tip        string `json:"tip"`
}

func RequestHoliday(config interface{}, date string) string {
	conf := config.(*Config)
	result := &holidayResult{}
	res := ms.RequestGet(conf.Url + "/jiejiari/index?mode=1&key=" + conf.Key + "&date=" + date)
	err := json.Unmarshal(res, &result)
	if err != nil {
		zap.L().Info("RequestHoliday序列化失败", zap.Error(err))
	}
	//if result.Code == 150 {
	//	return "今天天气机器人卡壳啦，请充值让我修复它吧，hhh"
	//}
	var info = result.Newslist[0]
	splitDate := strings.Split(info.Date, "-")
	formatDay, _ := strconv.Atoi(splitDate[2])
	formatDate := fmt.Sprintf("%s年%s月%d日", splitDate[0], splitDate[1], formatDay)

	var tip = fmt.Sprintf("你好：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;今天是公历%s，农历%s年%s%s，%s，今天是", formatDate, info.Lunaryear, info.Lunarmonth,
		info.Lunarday, info.Cnweekday)
	if info.Daycode == 1 {
		tip = tip + info.Name
	} else {
		tip = tip + info.Info
	}
	return tip

}
